package com.zr.planClass.service.impl;

import com.zr.planClass.mapper.KuCunMapper;
import com.zr.planClass.model.kucun.StoreTagQianDuanVo;
import com.zr.planClass.model.kucun.StoreTagVo;
import com.zr.planClass.service.KuCunService;
import com.zr.util.AllRecords;
import com.zr.util.ErrorMessageEnum;
import com.zr.util.ResultBuilderVo;
import com.zr.util.ResultVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by 非常狂躁的猪 on 2020/1/3.
 */
@Service
public class KuCunServiceImpl implements KuCunService {

    @Autowired
    private KuCunMapper kuCunMapper;


    @Override
    public ResultVo queryAllTag(StoreTagQianDuanVo storeTagQianDuanVo) {
        List<StoreTagVo> list = kuCunMapper.queryAllTag(storeTagQianDuanVo);
        List<StoreTagQianDuanVo> qianDuanVoList = new ArrayList<>();
        for (StoreTagVo s:list){
            StoreTagQianDuanVo storeTagQianDuanVo2 = new StoreTagQianDuanVo();
            storeTagQianDuanVo2.setCode(s.getStoreTagCode());
            storeTagQianDuanVo2.setName(s.getStoreTagName());
            storeTagQianDuanVo2.setRemark(s.getStoreTagRemark());
            storeTagQianDuanVo2.setStatus(s.getStoreTagStatus());
            if (s.getStoreTagStatus() == true){
                storeTagQianDuanVo2.setStatusName(ErrorMessageEnum.QIYONG.getName());

            }else {
                storeTagQianDuanVo2.setStatusName(ErrorMessageEnum.JINYONG.getName());
            }
            qianDuanVoList.add(storeTagQianDuanVo2);
        }

        int count = kuCunMapper.getCountAllTage(storeTagQianDuanVo);
        AllRecords allRecords = new AllRecords();
        allRecords.setDataList(qianDuanVoList);
        allRecords.setPageSize(storeTagQianDuanVo.getPageSize());
        allRecords.setPageIndex(storeTagQianDuanVo.getPageIndex());
        allRecords.setTotalNumber(count); //总共的条数
        allRecords.resetTotalNumber(count); //计算总页数

        return ResultBuilderVo.success(allRecords);
    }
}
